package com.yuncheng.spcyApi.controller;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.alog.utils.StringEmptyUtils;
import com.yuncheng.spcyApi.entity.SysUserFbwz;
import com.yuncheng.spcyApi.service.ISysUserFbwzService;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;

/**
 * 用户发表文章
 * @author hua
 */
@Api(tags = "审评查验-用户发表文章接口")
@RestController
@RequestMapping("/api/spzx-spcy/userFbwz")
public class SysUserFbwzController {

    @Resource
    private ISysUserFbwzService sysUserFbwzService;

    @Log(title = "用户发表文章-分页列表查询")
    @ApiOperation(value = "用户发表文章-分页列表查询")
    @GetMapping(value = "/pageList")
    public HttpResult<?> queryPageList(SysUserFbwz query, PageVo pageVo, OrderItemVo orderItemVo) {
        if (StringEmptyUtils.isBlank(query.getFuserid())){
            query.setFuserid(GetCurrentUserUtils.getCurrentUserId());
        }
        return HttpResult.ok(sysUserFbwzService.selectPageList(query, pageVo, orderItemVo));
    }

    @Log(title = "用户发表文章-所有列表")
    @ApiOperation(value = "用户发表文章-所有列表")
    @GetMapping(value = "/selectAllList")
    public HttpResult<?> selectAllList(SysUserFbwz query) {
        if (StringEmptyUtils.isBlank(query.getFuserid())){
            query.setFuserid(GetCurrentUserUtils.getCurrentUserId());
        }
        return HttpResultVo.HttpResultList(sysUserFbwzService.selectAllList(query));
    }

    @Log(title = "用户发表文章-添加")
    @ApiOperation(value = "用户发表文章-添加")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody SysUserFbwz bean) {
        if (StringEmptyUtils.isBlank(bean.getFuserid())){
            bean.setFuserid(GetCurrentUserUtils.getCurrentUserId());
        }
        return HttpResultVo.HttpResultSave(sysUserFbwzService.addFbwz(bean), "添加成功");
    }

    @Log(title = "用户发表文章-编辑")
    @ApiOperation(value = "用户发表文章-编辑")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody SysUserFbwz buffer) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {

        sysUserFbwzService.updatwFbwz(buffer);
        return HttpResult.ok("保存成功");
    }

    @Log(title = "用户发表文章-删除")
    @ApiOperation(value = "用户发表文章-删除")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam(value = "ids",defaultValue = "") String ids) {

        sysUserFbwzService.deleteFbwz(ids);
        return HttpResult.ok("删除成功");
    }

    @Log(title = "用户发表文章-根据id查询")
    @ApiOperation(value = "用户发表文章-根据id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam(value = "id",defaultValue = "") String id) {

        SysUserFbwz bean = sysUserFbwzService.getById(id);
        return HttpResult.ok(bean);
    }

}
